package at.ac.tuwien.prog.command;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import at.ac.tuwien.prog.entity.Register;
import at.ac.tuwien.prog.memory.IMemoryManager;
import at.ac.tuwien.prog.system.ISystem;

/**
 * 
 * Schreibe den Ihnalt von Register B in Register A (bzw. indirekter Sprung fuer A = -8192).
 * 
 * @author christoph.pickl@student.tuwien.ac.at
 */
public class SetValueCommand extends AbstractCommand {
	
	private static final Log LOG = LogFactory.getLog(SetValueCommand.class);

	public static final String NAME = "setv";

	public SetValueCommand(int targetAddress, int sourceAddress) {
		super(targetAddress, sourceAddress);
	}

	public void execute(final ISystem system) {
		final int targetAddress = this.getOperand1();
		final int sourceAddress = this.getOperand2();
		
		final IMemoryManager memory = system.getMemoryManager();

		final Register sourceValue = memory.getRegisterValue(sourceAddress);

		LOG.info("execute(targetAddress="+targetAddress+"; sourceAddress="+sourceAddress+") sourceValue="+sourceValue);
		
		memory.setRegisterValue(targetAddress, sourceValue);

	}

}
